<template>
  <basic-container>
    <div>
      <div class="w-50 m-t-20">
        <el-descriptions column="3" :colon="false" direction="vertical">
          <el-descriptions-item
            label="总计次数"
            content-class-name="c-blue f-s-20 lh-1"
            >kooriookami</el-descriptions-item
          >
          <el-descriptions-item
            label="销量（吨）"
            content-class-name="c-blue f-s-20 lh-1"
            >18100000000</el-descriptions-item
          >
          <el-descriptions-item
            label="销售额（元）"
            content-class-name="c-blue f-s-20 lh-1"
            >18100000000</el-descriptions-item
          >
        </el-descriptions>
      </div>
      <avue-crud
        :option="optionMachineSalesStatistics"
        :table-loading="loading"
        :data="data"
        :page="page"
        @row-del="rowDel"
        v-model="form"
        :permission="permissionList"
        @row-update="rowUpdate"
        @row-save="rowSave"
        :before-open="beforeOpen"
        @search-change="searchChange"
        @search-reset="searchReset"
        @selection-change="selectionChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @on-load="onLoad"
      >
        <template #menuRight>
          <el-button type="primary" size="small">报表下载</el-button>
        </template>
        <template #menuLeft>
          <el-form :inline="true" :model="query" class="search-form-inline">
            <el-form-item>
              <el-radio-group v-model="radio1" size="small">
                <el-radio-button label="昨日"></el-radio-button>
                <el-radio-button label="本月"></el-radio-button>
                <el-radio-button label="今年"></el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item>
              <el-date-picker
                size="small"
                v-model="searchDate"
                type="daterange"
                class="m-r-10"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </el-form-item>
            <el-form-item>
              <el-input placeholder="请输入搜索关键字" size="small" />
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                size="small"
                @click="conditionalQuery"
                :loading="loading"
                >查询</el-button
              >
            </el-form-item>
          </el-form>
        </template>
      </avue-crud>
    </div>
  </basic-container>
</template>

<script>
import { isListEmpty } from "@/util/common-util";
import {
  getList,
  summary,
} from "@/api/data-statistics/machine-sales-statistics";
import { optionMachineSalesStatistics } from "@/const/data-statistics/machine-sales-statistics";
import { mapGetters } from "vuex";

export default {
  data() {
    return {
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      optionMachineSalesStatistics,
      showSettingFlag: false,
      data: [],
      searchDate: null,
    };
  },
  computed: {
    ...mapGetters(["permission"]),
  },
  methods: {
    getSummary() {},
    //搜索查询
    conditionalQuery() {
      if (isListEmpty(this.searchDate)) {
        this.query.startTime = "";
        this.query.endTime = "";
      } else {
        this.query.startTime = this.searchDate[0];
        this.query.endTime = this.searchDate[1];
      }
      this.onLoad(this.page, this.query);
    },
    rowSave(row, done, loading) {
      add(row).then(
        () => {
          done();
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    rowUpdate(row, index, done, loading) {
      update(row).then(
        () => {
          done();
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        });
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(this.ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$refs.crud.toggleSelection();
        });
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        getDetail(this.form.id).then((res) => {
          this.form = res.data.data;
        });
      }
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
      });
      summary(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {});
    },
  },
};
</script>

<style lang="scss">
.search-form-inline .el-form-item {
  margin-bottom: 0;
}
.lh-1 {
  line-height: 20px !important;
  padding-bottom: 50px;
}
</style>
